%%%-------------------------------------------------------------------
%%% @author Rain
%%% @copyright (C) 2022, <COMPANY>
%%% @doc
%%%
%%% @end
%%% Created : 16. 5月 2022 10:40
%%%-------------------------------------------------------------------
-module(test_tower_aoi).
-author("Rain").
-include("obj.hrl").

%% API
-export([start_tower_aoi_svr/0,
        make_obj_svr/0,
        random_pos_enter/0,
        random_pos_enter2/1,
        test/0,
        random_pos_sync/0,
        random_uuid_leave/0]
            ).

-define(TEST_MAP_SIZE_X, 1000). %% 测试地图X轴长度
-define(TEST_MAP_SIZE_Y, 1000). %% 测试地图Y轴长度
-define(TEST_OBJ_FIRST_ID, 10000). %% 测试Object第一个ID
-define(TEST_OBJ_LAST_ID, ?TEST_OBJ_FIRST_ID + ?TEST_OBJ_NUM - 1). %% 测试Object最后一个ID
-define(TEST_OBJ_NUM, 4). %% 测试Object数量


make_obj_svr() ->
    [obj_svr:start_obj_svr(Uuid)||Uuid<-lists:seq(10000, 10003)].

start_tower_aoi_svr() ->
    tower_aoi_svr:start_map(?TEST_MAP_SIZE_X, ?TEST_MAP_SIZE_Y),
    tower_aoi_brocast_svr:start_broadcast().

random_pos_enter() ->
    [begin
         io:format("测试：通知Uid(~p)进入随机坐标 ~n",[Uid]),
         ?OBJ_SVR(Uid) ! {enter_map, rand:uniform(?TEST_MAP_SIZE_X), rand:uniform(?TEST_MAP_SIZE_Y)},
         io:format("Uid(~p)进入随机坐标通知结束，等待1s~n", [Uid]),
         timer:sleep(1000)
     end||Uid<-lists:seq(?TEST_OBJ_FIRST_ID, ?TEST_OBJ_LAST_ID)].

random_pos_enter2(Uuid) ->
    ?OBJ_SVR(Uuid) ! {enter_map, rand:uniform(?TEST_MAP_SIZE_X), rand:uniform(?TEST_MAP_SIZE_Y)}.


random_pos_sync() ->
    RandUuid = rand_int(?TEST_OBJ_FIRST_ID, ?TEST_OBJ_LAST_ID),
    ?OBJ_SVR(RandUuid) ! {sync_map, rand:uniform(?TEST_MAP_SIZE_X), rand:uniform(?TEST_MAP_SIZE_Y)},
    ok.

random_uuid_leave() ->
    RandUuid = rand_int(?TEST_OBJ_FIRST_ID, ?TEST_OBJ_LAST_ID),
    ?OBJ_SVR(RandUuid) ! leave_map.

rand_int(From, To) when From < To ->
    From1 = From - 1,
    rand:uniform(To - From1) + From1.

test() ->
    start_tower_aoi_svr(),
    make_obj_svr(),
    random_pos_enter(),
    ok.




